Skip to content

Commit

Permalink
add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
roncodingenthusiast committed Mar 6, 2023
1 parent f47fbf7 commit bf9fb37
Showing 1 changed file with 50 additions and 1 deletion.
51 changes: 50 additions & 1 deletion command/acl/token/update/token_update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,19 @@ func TestTokenUpdateCommand(t *testing.T) {

// create a token
token, _, err := client.ACL().TokenCreate(
&api.ACLToken{Description: "test"},
&api.ACLToken{Description: "test",
NodeIdentities: []*api.ACLNodeIdentity{
{
NodeName: "first-node",
Datacenter: "middleearth-southwest",
},
},
ServiceIdentities: []*api.ACLServiceIdentity{
{
ServiceName: "fake-service",
},
},
},
&api.WriteOptions{Token: "root"},
)
require.NoError(t, err)
Expand Down Expand Up @@ -135,6 +147,22 @@ func TestTokenUpdateCommand(t *testing.T) {
require.Len(t, token.Policies, 1)
})

// update with service-identity
t.Run("service-identity", func(t *testing.T) {
require.Len(t, token.ServiceIdentities, 1)

token := run(t, []string{
"-http-addr=" + a.HTTPAddr(),
"-accessor-id=" + token.AccessorID,
"-token=root",
"-service-identity=service:datapalace",
"-description=test token",
})

require.Len(t, token.ServiceIdentities, 1)
require.Equal(t, "service", token.ServiceIdentities[0].ServiceName)
})

// update with no description shouldn't delete the current description
t.Run("merge-description", func(t *testing.T) {
token := run(t, []string{
Expand Down Expand Up @@ -186,6 +214,11 @@ func TestTokenUpdateCommandWithAppend(t *testing.T) {
Datacenter: "middleearth-southwest",
},
},
ServiceIdentities: []*api.ACLServiceIdentity{
{
ServiceName: "fake-service",
},
},
},
&api.WriteOptions{Token: "root"},
)
Expand Down Expand Up @@ -260,6 +293,22 @@ func TestTokenUpdateCommandWithAppend(t *testing.T) {
require.Equal(t, "foo", token.NodeIdentities[1].NodeName)
require.Equal(t, "bar", token.NodeIdentities[1].Datacenter)
})

// update with append-service-identity
t.Run("append-service-identity", func(t *testing.T) {
require.Len(t, token.ServiceIdentities, 1)

token := run(t, []string{
"-http-addr=" + a.HTTPAddr(),
"-accessor-id=" + token.AccessorID,
"-token=root",
"-append-service-identity=service:datapalace",
"-description=test token",
})

require.Len(t, token.ServiceIdentities, 2)
require.Equal(t, "service", token.ServiceIdentities[1].ServiceName)
})
}

func TestTokenUpdateCommand_JSON(t *testing.T) {
Expand Down

0 comments on commit bf9fb37

Please sign in to comment.