Skip to content

Commit

Permalink
Merge pull request flyteorg#79 from lyft/fairness-hard-cap
Browse files Browse the repository at this point in the history
Fix token format and add unit tests
  • Loading branch information
bnsblue authored Mar 5, 2020
2 parents f8e88ac + e18dfea commit 8c952d4
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func composeNamespaceScopePrefix(id *core.TaskExecutionIdentifier) TokenPrefix {
}

func composeExecutionScopePrefix(id *core.TaskExecutionIdentifier) TokenPrefix {
return composeNamespaceScopePrefix(id).extend(id.GetNodeExecutionId().GetExecutionId().GetProject())
return composeNamespaceScopePrefix(id).extend(id.GetNodeExecutionId().GetExecutionId().GetName())
}

func ComposeTokenPrefix(id *core.TaskExecutionIdentifier) TokenPrefix {
Expand Down
55 changes: 55 additions & 0 deletions pkg/controller/nodes/task/resourcemanager/resourcemanager_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package resourcemanager

import (
"testing"

"github.com/lyft/flyteidl/gen/pb-go/flyteidl/core"
)

func TestComposeTokenPrefix(t *testing.T) {
type args struct {
id *core.TaskExecutionIdentifier
}
tests := []struct {
name string
args args
want TokenPrefix
}{
{name: "composing the prefix from task execution id",
args: args{id: &core.TaskExecutionIdentifier{
TaskId: nil,
NodeExecutionId: &core.NodeExecutionIdentifier{ExecutionId: &core.WorkflowExecutionIdentifier{Project: "testproject", Domain: "testdomain", Name: "testname"}},
}},
want: TokenPrefix("ex:testproject:testdomain:testname"),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := ComposeTokenPrefix(tt.args.id); got != tt.want {
t.Errorf("ComposeTokenPrefix() = %v, want %v", got, tt.want)
}
})
}
}

func TestToken_prepend(t *testing.T) {
type args struct {
prefix TokenPrefix
}
tests := []struct {
name string
t Token
args args
want Token
}{
{name: "Prepend should prepend", t: Token("abcdefg-hijklmn"), args: args{prefix: TokenPrefix("tok:prefix")},
want: Token("tok:prefix-abcdefg-hijklmn")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.t.prepend(tt.args.prefix); got != tt.want {
t.Errorf("prepend() = %v, want %v", got, tt.want)
}
})
}
}

0 comments on commit 8c952d4

Please sign in to comment.