File: gob_test.go

package info (click to toggle)
golang-go.uber-mock 0.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,176 kB
  • sloc: sh: 37; makefile: 3
file content (31 lines) | stat: -rw-r--r-- 724 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package main

import (
	"encoding/gob"
	"os"
	"path/filepath"
	"testing"

	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

func TestGobMode(t *testing.T) {

	// Encode a package to a temporary gob.
	parser := packageModeParser{}
	want, err := parser.parsePackage(
		"go.uber.org/mock/mockgen/internal/tests/package_mode" /* package name */,
		[]string{ "Human", "Earth" } /* ifaces */,
	)
	path := filepath.Join(t.TempDir(), "model.gob")
	outfile, err := os.Create(path)
	require.NoError(t, err)
	require.NoError(t, gob.NewEncoder(outfile).Encode(want))
	outfile.Close()

	// Ensure gobMode loads it correctly.
	got, err := gobMode(path)
	require.NoError(t, err)
	assert.Equal(t, want, got)
}