Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions cmd/integrations/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"bytes"
"errors"
"flag"
"io"
"os"
Expand All @@ -13,6 +14,12 @@ import (
"github.com/winhowes/AuthTranslator/cmd/integrations/plugins"
)

type marshalError struct{}

func (marshalError) MarshalYAML() (interface{}, error) {
return nil, errors.New("marshal failure")
}

func TestAddUpdateDeleteList(t *testing.T) {
dir := t.TempDir()
cfgFile := filepath.Join(dir, "config.yaml")
Expand Down Expand Up @@ -204,6 +211,16 @@ func TestWriteConfigError(t *testing.T) {
}
}

func TestWriteConfigMarshalError(t *testing.T) {
err := writeConfig([]plugins.Integration{{
Name: "bad",
IncomingAuth: []plugins.AuthPluginConfig{{Params: map[string]interface{}{"fail": marshalError{}}}},
}})
if err == nil {
t.Fatalf("expected marshal error")
}
}

func TestWriteConfigSuccess(t *testing.T) {
dir := t.TempDir()
cfg := filepath.Join(dir, "cfg.yaml")
Expand Down Expand Up @@ -442,6 +459,20 @@ func TestDeleteIntegrationWriteError(t *testing.T) {
}
}

func TestDeleteIntegrationReadError(t *testing.T) {
dir := t.TempDir()
// Point to a directory so readConfig fails before writeConfig is attempted.
cmd := exec.Command(os.Args[0], "-test.run=TestDeleteIntegrationHelper", "--")
cmd.Env = append(os.Environ(), "GO_WANT_DELETE_HELPER=1", "CFG="+dir)
out, err := cmd.CombinedOutput()
if err == nil {
t.Fatalf("expected error")
}
if len(out) == 0 {
t.Fatalf("expected error output")
}
}

func TestMainUpdateUnknownPlugin(t *testing.T) {
cmd := exec.Command(os.Args[0], "-test.run=TestMainHelper", "--", "update", "nop")
cmd.Env = append(os.Environ(), "GO_WANT_INTEGRATIONS_HELPER=1")
Expand Down
Loading