-
Notifications
You must be signed in to change notification settings - Fork 878
chore: join owner, template, and org in new workspace view #15116
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
4967b6b
chore: new workspace view to join in owner, template, and org
Emyrk 15d24fb
random text got added
Emyrk a3ea2bd
add unit test to verify subset of fields
Emyrk d3bebae
remove unused
Emyrk ba8077d
Revert "remove unused"
Emyrk 90f2474
add guard rail
Emyrk 50fb160
more test fixes
Emyrk f18c801
fix dgen calls
Emyrk b231af9
fixup audit track and workspacebuildData call
Emyrk ba01ba0
bump migration number
Emyrk b216efd
fix more tests
Emyrk d13fd10
fmt
Emyrk d48c231
continue fixing references to Workspace/WorkspaceTable
Emyrk 8be63e7
linting:
Emyrk a80a01d
make gen
Emyrk 5ad6a58
sql spaces...
Emyrk 9f6f5ee
make gen
Emyrk c48f327
fix audit panic
Emyrk 81a8aa2
fix audit test
Emyrk 50638c7
populate sdk workspace
Emyrk 6e448d8
rebase fixes
Emyrk 05ce1ae
fix workspace reference
Emyrk c8de158
static time
Emyrk File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add unit test to verify subset of fields
- Loading branch information
commit a3ea2bddb0b02cca075d0bd4bcfb0f645f10849b
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,139 @@ | ||
package testutil | ||
|
||
import ( | ||
"fmt" | ||
"reflect" | ||
"time" | ||
) | ||
|
||
type Random struct { | ||
String func() string | ||
Bool func() bool | ||
Int func() int64 | ||
Uint func() uint64 | ||
Float func() float64 | ||
Complex func() complex128 | ||
} | ||
|
||
func NewRandom() *Random { | ||
// Guaranteed to be random... | ||
return &Random{ | ||
String: func() string { return "foo" }, | ||
Bool: func() bool { return true }, | ||
Int: func() int64 { return 500 }, | ||
Uint: func() uint64 { return 126 }, | ||
Float: func() float64 { return 3.14 }, | ||
Complex: func() complex128 { return 6.24 }, | ||
} | ||
} | ||
|
||
// PopulateStruct does a best effort to populate a struct with random values. | ||
func PopulateStruct(s interface{}, r *Random) error { | ||
if r == nil { | ||
r = NewRandom() | ||
} | ||
|
||
v := reflect.ValueOf(s) | ||
if v.Kind() != reflect.Ptr || v.IsNil() { | ||
return fmt.Errorf("s must be a non-nil pointer") | ||
} | ||
|
||
v = v.Elem() | ||
if v.Kind() != reflect.Struct { | ||
return fmt.Errorf("s must be a pointer to a struct") | ||
} | ||
|
||
t := v.Type() | ||
for i := 0; i < t.NumField(); i++ { | ||
field := t.Field(i) | ||
fieldName := field.Name | ||
|
||
fieldValue := v.Field(i) | ||
if !fieldValue.CanSet() { | ||
continue // Skip if field is unexported | ||
} | ||
|
||
nv, err := populateValue(fieldValue, r) | ||
if err != nil { | ||
return fmt.Errorf("%s : %w", fieldName, err) | ||
} | ||
v.Field(i).Set(nv) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func populateValue(v reflect.Value, r *Random) (reflect.Value, error) { | ||
var err error | ||
|
||
// Handle some special cases | ||
switch v.Type() { | ||
case reflect.TypeOf(time.Time{}): | ||
v.Set(reflect.ValueOf(time.Date(2020, 5, 2, 5, 19, 21, 30, time.UTC))) | ||
return v, nil | ||
Emyrk marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
switch v.Kind() { | ||
case reflect.Struct: | ||
if err := PopulateStruct(v.Addr().Interface(), r); err != nil { | ||
return v, err | ||
} | ||
case reflect.String: | ||
v.SetString(r.String()) | ||
case reflect.Bool: | ||
v.SetBool(true) | ||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64: | ||
v.SetInt(r.Int()) | ||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64: | ||
v.SetUint(r.Uint()) | ||
case reflect.Float32, reflect.Float64: | ||
v.SetFloat(r.Float()) | ||
case reflect.Complex64, reflect.Complex128: | ||
v.SetComplex(r.Complex()) | ||
case reflect.Array: | ||
for i := 0; i < v.Len(); i++ { | ||
nv, err := populateValue(v.Index(i), r) | ||
if err != nil { | ||
return v, fmt.Errorf("array index %d : %w", i, err) | ||
} | ||
v.Index(i).Set(nv) | ||
} | ||
case reflect.Map: | ||
m := reflect.MakeMap(v.Type()) | ||
|
||
// Set a value in the map | ||
k := reflect.New(v.Type().Key()) | ||
kv := reflect.New(v.Type().Elem()) | ||
k, err = populateValue(k, r) | ||
if err != nil { | ||
return v, fmt.Errorf("map key : %w", err) | ||
} | ||
kv, err = populateValue(kv, r) | ||
if err != nil { | ||
return v, fmt.Errorf("map value : %w", err) | ||
} | ||
|
||
m.SetMapIndex(k, kv) | ||
return m, nil | ||
case reflect.Pointer: | ||
return populateValue(v.Elem(), r) | ||
case reflect.Slice: | ||
s := reflect.MakeSlice(v.Type(), 2, 2) | ||
sv, err := populateValue(reflect.New(v.Type().Elem()), r) | ||
if err != nil { | ||
return v, fmt.Errorf("slice value : %w", err) | ||
} | ||
|
||
s.Index(0).Set(sv) | ||
s.Index(1).Set(sv) | ||
//reflect.AppendSlice(s, sv) | ||
|
||
return s, nil | ||
case reflect.Uintptr, reflect.UnsafePointer, reflect.Chan, reflect.Func, reflect.Interface: | ||
// Unsupported | ||
return v, fmt.Errorf("%s is not supported", v.Kind()) | ||
default: | ||
return v, fmt.Errorf("unsupported kind %s", v.Kind()) | ||
} | ||
return v, nil | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: use a non-UTC timezone
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am going to be lazy here.