MCPcopy
hub / github.com/google/mtail / TestDatumFetchInstrs

Function TestDatumFetchInstrs

internal/runtime/vm/vm_test.go:811–877  ·  view source on GitHub ↗

code.Instructions with datum retrieve.

(t *testing.T)

Source from the content-addressed store, hash-verified

809
810// code.Instructions with datum retrieve.
811func TestDatumFetchInstrs(t *testing.T) {
812 var m []*metrics.Metric
813 m = append(m,
814 metrics.NewMetric("a", "tst", metrics.Counter, metrics.Int),
815 metrics.NewMetric("b", "tst", metrics.Counter, metrics.Float),
816 metrics.NewMetric("c", "tst", metrics.Text, metrics.String))
817
818 {
819 // iget
820 v := makeVM(code.Instr{code.Iget, nil, 0}, m)
821 d, err := m[0].GetDatum()
822 testutil.FatalIfErr(t, err)
823 datum.SetInt(d, 37, time.Now())
824 v.t.Push(d)
825 v.execute(v.t, v.prog[0])
826 if v.terminate {
827 t.Fatalf("Execution failed, see info log.")
828 }
829 i, err := v.t.PopInt()
830 if err != nil {
831 t.Fatalf("Execution failed, see info; %v", err)
832 }
833 if i != 37 {
834 t.Errorf("unexpected value %d", i)
835 }
836 }
837
838 {
839 // fget
840 v := makeVM(code.Instr{code.Fget, nil, 0}, m)
841 d, err := m[1].GetDatum()
842 testutil.FatalIfErr(t, err)
843 datum.SetFloat(d, 12.1, time.Now())
844 v.t.Push(d)
845 v.execute(v.t, v.prog[0])
846 if v.terminate {
847 t.Fatalf("Execution failed, see info log.")
848 }
849 i, err := v.t.PopFloat()
850 if err != nil {
851 t.Fatalf("Execution failed, see info: %v", err)
852 }
853 if i != 12.1 {
854 t.Errorf("unexpected value %f", i)
855 }
856 }
857
858 {
859 // sget
860 v := makeVM(code.Instr{code.Sget, nil, 0}, m)
861 d, err := m[2].GetDatum()
862 testutil.FatalIfErr(t, err)
863 datum.SetString(d, "aba", time.Now())
864 v.t.Push(d)
865 v.execute(v.t, v.prog[0])
866 if v.terminate {
867 t.Fatalf("Execution failed, see info log.")
868 }

Callers

nothing calls this directly

Calls 12

NewMetricFunction · 0.92
FatalIfErrFunction · 0.92
SetIntFunction · 0.92
SetFloatFunction · 0.92
SetStringFunction · 0.92
makeVMFunction · 0.85
GetDatumMethod · 0.80
PushMethod · 0.80
executeMethod · 0.80
PopIntMethod · 0.80
PopFloatMethod · 0.80
PopStringMethod · 0.80

Tested by

no test coverage detected