Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return ErrNotFound when Connectivity Template does not exist #97

Merged
merged 1 commit into from
Aug 20, 2023
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions apstra/talk_to_apstra.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ func convertTtaeToAceWherePossible(err error) error {
return ApstraClientErr{errType: ErrExists, err: errors.New(ttae.Msg)}
case strings.Contains(ttae.Msg, "Transformation cannot be changed"):
return ApstraClientErr{errType: ErrCannotChangeTransform, err: errors.New(ttae.Msg)}
case strings.Contains(ttae.Msg, "does not exist"):
return ApstraClientErr{errType: ErrNotfound, err: errors.New(ttae.Msg)}
}
case http.StatusInternalServerError:
switch {
Expand Down
42 changes: 42 additions & 0 deletions apstra/two_stage_l3_clos_connectivity_template_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,3 +451,45 @@ func TestCtLayout(t *testing.T) {
}
}
}

func TestConnectivityTemplate404(t *testing.T) {
ctx := context.Background()

clients, err := getTestClients(ctx, t)
if err != nil {
t.Fatal(err)
}

for _, client := range clients {
bpClient, bpDel := testBlueprintA(ctx, t, client.client)
if err != nil {
t.Fatal(err)
}
defer func() {
err := bpDel(ctx)
if err != nil {
t.Fatal(err)
}
}()

_, err = bpClient.GetConnectivityTemplate(ctx, "bogus")
if err == nil {
t.Fatal("retrieval of bogus CT should have produced an error")
} else {
var ace ApstraClientErr
if !errors.As(err, &ace) || ace.Type() != ErrNotfound {
t.Fatal("error should have been something 404-ish")
}
}

err = bpClient.DeleteConnectivityTemplate(ctx, "bogus")
if err == nil {
t.Fatal("deletion of bogus CT should have produced an error")
} else {
var ace ApstraClientErr
if !errors.As(err, &ace) || ace.Type() != ErrNotfound {
t.Fatal("error should have been something 404-ish")
}
}
}
}