Skip to content

Commit 72d8788

Browse files
committed
add -update flag to update goldens
1 parent 3d6a2e6 commit 72d8788

File tree

7 files changed

+27
-20
lines changed

7 files changed

+27
-20
lines changed

scripts/apitypings/main_test.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
package main
88

99
import (
10-
"fmt"
10+
"flag"
1111
"os"
1212
"path/filepath"
1313
"strings"
@@ -16,6 +16,9 @@ import (
1616
"github.com/stretchr/testify/require"
1717
)
1818

19+
// updateGoldenFiles is a flag that can be set to update golden files.
20+
var updateGoldenFiles = flag.Bool("update", false, "Update golden files")
21+
1922
func TestGeneration(t *testing.T) {
2023
t.Parallel()
2124
files, err := os.ReadDir("testdata")
@@ -38,8 +41,12 @@ func TestGeneration(t *testing.T) {
3841
require.NoErrorf(t, err, "read file %s", golden)
3942
expectedString := strings.TrimSpace(string(expected))
4043
output = strings.TrimSpace(output)
41-
fmt.Println(string(output))
42-
require.Equal(t, expectedString, output, "matched output")
44+
if *updateGoldenFiles {
45+
err := os.WriteFile(golden, []byte(output), 0644)
46+
require.NoError(t, err, "write golden file")
47+
} else {
48+
require.Equal(t, expectedString, output, "matched output")
49+
}
4350
})
4451
}
4552
}

scripts/apitypings/testdata/enums/enums.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package codersdk
22

33
type (
4-
Enum string
5-
Enums []Enum
4+
Enum string
5+
EnumSliceType []Enum
66
)
77

88
const (

scripts/apitypings/testdata/enums/enums.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// From codersdk/enums.go
2-
export type Enums = readonly Enum[]
2+
export type EnumSliceType = (readonly Enum[])
33

44
// From codersdk/enums.go
55
export type Enum = "bar" | "baz" | "foo" | "qux"

scripts/apitypings/testdata/genericmap/genericmap.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
package codersdk
22

3-
type Foo struct {
4-
Bar string `json:"bar"`
5-
}
6-
73
type Buzz struct {
84
Foo `json:"foo"`
95
Bazz string `json:"bazz"`
106
}
117

12-
type Custom interface {
13-
Foo | Buzz
8+
type Foo struct {
9+
Bar string `json:"bar"`
1410
}
1511

1612
type FooBuzz[R Custom] struct {
1713
Something []R `json:"something"`
1814
}
1915

16+
type Custom interface {
17+
Foo | Buzz
18+
}
19+
2020
// Not yet supported
2121
//type FooBuzzMap[R Custom] struct {
2222
// Something map[string]R `json:"something"`

scripts/apitypings/testdata/genericmap/genericmap.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ export interface Foo {
1111

1212
// From codersdk/genericmap.go
1313
export interface FooBuzz<R extends Custom> {
14-
readonly something: readonly R[]
14+
readonly something: (readonly R[])
1515
}
1616

1717
// From codersdk/genericmap.go
18-
export type Custom = Foo | Buzz
18+
export type Custom = Foo | Buzz

scripts/apitypings/testdata/generics/generics.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ export interface Static {
3333
}
3434

3535
// From codersdk/generics.go
36-
export type Custom = string | boolean | number | readonly string[] | null
36+
export type Custom = string | boolean | number | (readonly string[]) | null
3737

3838
// From codersdk/generics.go
3939
export type Single = string
4040

41-
export type comparable = boolean | number | string | any
41+
export type comparable = boolean | number | string | any
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
// From codersdk/genericslice.go
22
export interface Bar {
3-
readonly Bar: string
3+
readonly Bar: string
44
}
55

66
// From codersdk/genericslice.go
77
export interface Foo<R extends any> {
8-
readonly Slice: readonly R[]
9-
readonly TwoD: readonly (readonly R[])[]
10-
}
8+
readonly Slice: (readonly R[])
9+
readonly TwoD: (readonly (readonly R[])[])
10+
}

0 commit comments

Comments
 (0)