Skip to content

Commit

Permalink
trigger tests
Browse files Browse the repository at this point in the history
  • Loading branch information
kaatinga committed Mar 12, 2024
1 parent f8627c2 commit f8ea7aa
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 32 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/checkout@v5
- name: Set up Go
uses: actions/setup-go@v4
uses: actions/setup-go@v5
with:
go-version: '1.21'
- name: Build
Expand Down
66 changes: 36 additions & 30 deletions models_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,47 +29,53 @@ func TestCrusoe_Call(t *testing.T) {
}

func TestCrusoe_Get_Int(t *testing.T) {
tests := []struct {
var tests []struct {
value int
want *robinson.Crusoe[int]
}{
{123, &robinson.Crusoe[int]{}},
{456, &robinson.Crusoe[int]{}},
{789, &robinson.Crusoe[int]{}},
{1, &robinson.Crusoe[int]{}},
{2, &robinson.Crusoe[int]{}},
}

// fuzzing
for i := 0; i < 1000; i++ {
tests = append(tests, struct{ value int }{value: i})
}

crusoe := robinson.NewCrusoe[int]()
if fmt.Sprintf("%[1]T", crusoe) != "*robinson.Crusoe[int]" {
t.Errorf("strange cache type returned: %T", crusoe)
}
for _, scenario := range tests {
t.Run(fmt.Sprintf("%T %[1]v", scenario.value), func(t *testing.T) {
crusoe.Set(scenario.value)
cacheValue := crusoe.Get()
if fmt.Sprintf("%[1]T", cacheValue) != "int" {
t.Errorf("strange value type returned: %T", cacheValue)
}
})
}

{
cacheValue := crusoe.Get()
if cacheValue != tests[len(tests)-1].value {
t.Errorf("strange value returned: %v", cacheValue)
go func() {
for _, scenario := range tests {
t.Run(fmt.Sprintf("%T %[1]v", scenario.value), func(t *testing.T) {
crusoe.Set(scenario.value)
cacheValue := crusoe.Get()
if fmt.Sprintf("%[1]T", cacheValue) != "int" {
t.Errorf("strange value type returned: %T", cacheValue)
}
})
}
}
}()

for _, scenario := range tests {
t.Run(fmt.Sprintf("%T %[1]v", scenario.value), func(t *testing.T) {
crusoe.Set(scenario.value)
go func() {
t.Run(fmt.Sprintf("get the last value"), func(t *testing.T) {

Check failure on line 59 in models_test.go

View workflow job for this annotation

GitHub Actions / lint

S1039: unnecessary use of fmt.Sprintf (gosimple)
cacheValue := crusoe.Get()
if fmt.Sprintf("%[1]T", cacheValue) != "int" {
t.Errorf("strange value type returned: %T", cacheValue)
}
if cacheValue != scenario.value {
if cacheValue != tests[len(tests)-1].value {
t.Errorf("strange value returned: %v", cacheValue)
}
})
}
}()

go func() {
for _, scenario := range tests {
t.Run(fmt.Sprintf("%T %[1]v", scenario.value), func(t *testing.T) {
crusoe.Set(scenario.value)
cacheValue := crusoe.Get()
if fmt.Sprintf("%[1]T", cacheValue) != "int" {
t.Errorf("strange value type returned: %T", cacheValue)
}
if cacheValue != scenario.value {
t.Errorf("strange value returned: %v", cacheValue)
}
})
}
}()
}

0 comments on commit f8ea7aa

Please sign in to comment.