github.com/grailbio/bigslice@v0.0.0-20230519005545-30c4c12152ad/frame/ops_test.go (about)

     1  // Copyright 2019 GRAIL, Inc. All rights reserved.
     2  // Use of this source code is governed by the Apache 2.0
     3  // license that can be found in the LICENSE file.
     4  
     5  package frame_test
     6  
     7  import (
     8  	"strings"
     9  	"testing"
    10  
    11  	"github.com/grailbio/bigslice/frame"
    12  )
    13  
    14  type testType struct{}
    15  
    16  func TestDoubleRegistration(t *testing.T) {
    17  	frame.RegisterOps(func(slice []testType) frame.Ops { return frame.Ops{} })
    18  	message := func() (err interface{}) {
    19  		defer func() {
    20  			err = recover()
    21  		}()
    22  		frame.RegisterOps(func(slice []testType) frame.Ops { return frame.Ops{} })
    23  		return nil
    24  	}()
    25  	if message == nil {
    26  		t.Fatal("expected panic")
    27  	}
    28  	if message, ok := message.(string); ok {
    29  		if !strings.HasPrefix(message, "frame.RegisterOps: ") || !strings.HasSuffix(message, "ops_test.go:17") {
    30  			t.Errorf("wrong message %s", message)
    31  		}
    32  	} else {
    33  		t.Errorf("wrong type %T for panic", message)
    34  	}
    35  }