- 
                Notifications
    You must be signed in to change notification settings 
- Fork 711
[CI] Tigron breakout 2: remove gotest.tools assert dependency internally #4042
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 all commits
      Commits
    
    
            Show all changes
          
          
            2 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      
    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
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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,169 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package assertive | ||
|  | ||
| import ( | ||
| "errors" | ||
| "strings" | ||
| "time" | ||
| ) | ||
|  | ||
| type testingT interface { | ||
| Helper() | ||
| FailNow() | ||
| Fail() | ||
| Log(args ...interface{}) | ||
| } | ||
|  | ||
| // ErrorIsNil immediately fails a test if err is not nil. | ||
| func ErrorIsNil(t testingT, err error, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if err != nil { | ||
| t.Log("expecting nil error, but got:", err) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // ErrorIs immediately fails a test if err is not the comparison error. | ||
| func ErrorIs(t testingT, err, compErr error, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if !errors.Is(err, compErr) { | ||
| t.Log("expected error to be:", compErr, "- instead it is:", err) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // IsEqual immediately fails a test if the two interfaces are not equal. | ||
| func IsEqual(t testingT, actual, expected interface{}, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if !isEqual(t, actual, expected) { | ||
| t.Log("expected:", actual, " - to be equal to:", expected) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // IsNotEqual immediately fails a test if the two interfaces are equal. | ||
| func IsNotEqual(t testingT, actual, expected interface{}, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if isEqual(t, actual, expected) { | ||
| t.Log("expected:", actual, " - to be equal to:", expected) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // StringContains immediately fails a test if the actual string does not contain the other string. | ||
| func StringContains(t testingT, actual, contains string, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if !strings.Contains(actual, contains) { | ||
| t.Log("expected:", actual, " - to contain:", contains) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // StringDoesNotContain immediately fails a test if the actual string contains the other string. | ||
| func StringDoesNotContain(t testingT, actual, contains string, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if strings.Contains(actual, contains) { | ||
| t.Log("expected:", actual, " - to NOT contain:", contains) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // StringHasSuffix immediately fails a test if the string does not end with suffix. | ||
| func StringHasSuffix(t testingT, actual, suffix string, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if !strings.HasSuffix(actual, suffix) { | ||
| t.Log("expected:", actual, " - to end with:", suffix) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // StringHasPrefix immediately fails a test if the string does not start with prefix. | ||
| func StringHasPrefix(t testingT, actual, prefix string, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if !strings.HasPrefix(actual, prefix) { | ||
| t.Log("expected:", actual, " - to start with:", prefix) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // DurationIsLessThan immediately fails a test if the duration is more than the reference. | ||
| func DurationIsLessThan(t testingT, actual, expected time.Duration, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if actual >= expected { | ||
| t.Log("expected:", actual, " - to be less than:", expected) | ||
| failNow(t, msg...) | ||
| } | ||
| } | ||
|  | ||
| // True immediately fails a test if the boolean is not true... | ||
| func True(t testingT, comp bool, msg ...string) bool { | ||
| t.Helper() | ||
|  | ||
| if !comp { | ||
| failNow(t, msg...) | ||
| } | ||
|  | ||
| return comp | ||
| } | ||
|  | ||
| // Check marks a test as failed if the boolean is not true (safe in go routines) | ||
| // | ||
| //nolint:varnamelen | ||
| func Check(t testingT, comp bool, msg ...string) bool { | ||
| t.Helper() | ||
|  | ||
| if !comp { | ||
| for _, m := range msg { | ||
| t.Log(m) | ||
| } | ||
|  | ||
| t.Fail() | ||
| } | ||
|  | ||
| return comp | ||
| } | ||
|  | ||
| //nolint:varnamelen | ||
| func failNow(t testingT, msg ...string) { | ||
| t.Helper() | ||
|  | ||
| if len(msg) > 0 { | ||
| for _, m := range msg { | ||
| t.Log(m) | ||
| } | ||
| } | ||
|  | ||
| t.FailNow() | ||
| } | ||
|  | ||
| func isEqual(t testingT, actual, expected interface{}) bool { | ||
| t.Helper() | ||
|  | ||
| // FIXME: this is risky and limited. Right now this is fine internally, but do better if this | ||
| // becomes public. | ||
| return actual == expected | ||
| } | ||
  
    
      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,48 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| package assertive_test | ||
|  | ||
| import ( | ||
| "errors" | ||
| "fmt" | ||
| "testing" | ||
|  | ||
| "github.com/containerd/nerdctl/mod/tigron/internal/assertive" | ||
| ) | ||
|  | ||
| func TestY(t *testing.T) { | ||
| t.Parallel() | ||
|  | ||
| var err error | ||
|  | ||
| assertive.ErrorIsNil(t, err) | ||
|  | ||
| //nolint:err113 | ||
| someErr := errors.New("test error") | ||
|  | ||
| err = fmt.Errorf("wrap: %w", someErr) | ||
| assertive.ErrorIs(t, err, someErr) | ||
|  | ||
| foo := "foo" | ||
| assertive.IsEqual(t, foo, "foo") | ||
|  | ||
| bar := 10 | ||
| assertive.IsEqual(t, bar, 10) | ||
|  | ||
| baz := true | ||
| assertive.IsEqual(t, baz, true) | ||
| } | 
  
    
      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,22 @@ | ||
| /* | ||
| Copyright The containerd Authors. | ||
|  | ||
| Licensed under the Apache License, Version 2.0 (the "License"); | ||
| you may not use this file except in compliance with the License. | ||
| You may obtain a copy of the License at | ||
|  | ||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|  | ||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|  | ||
| // Package assertive is an experimental, zero-dependencies assert library. | ||
| // Right now, it is not public and meant to be used only inside tigron. | ||
| // Consumers of tigron are free to use whatever assert library they want. | ||
| // In the future, this may become public for peeps who want `assert` to be | ||
| // bundled in. | ||
| package assertive | 
  
    
      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
    
  
  
    
              
  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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.