diff --git a/cmd/integrations/main_test.go b/cmd/integrations/main_test.go index d059987..7121775 100644 --- a/cmd/integrations/main_test.go +++ b/cmd/integrations/main_test.go @@ -2,6 +2,7 @@ package main import ( "bytes" + "errors" "flag" "io" "os" @@ -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") @@ -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") @@ -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")